from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QAbstractItemView
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt5agg import (FigureCanvasQTAgg as FigureCanvas)

from icon import icon


# "数据管理"直流电则测试仪的widget
class M_DCR_Widget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(M_DCR_Widget, self).__init__(parent)

        self.setObjectName("m_dcr_widget")
        self.setMinimumHeight(300)
        self.mainLayout = QtWidgets.QVBoxLayout(self)
        self.mainLayout.setObjectName("mainLayout")

        self.horizontalLayout_37 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_37.setObjectName("horizontalLayout_37")

        self.widget_52 = QtWidgets.QWidget(self)
        self.widget_52.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.widget_52.setAutoFillBackground(False)
        self.widget_52.setObjectName("widget_52")
        self.horizontalLayout_39 = QtWidgets.QHBoxLayout(self.widget_52)
        self.horizontalLayout_39.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_39.setSpacing(0)
        self.horizontalLayout_39.setObjectName("horizontalLayout_39")

        # Label Unfold
        self.label_Unfold = QtWidgets.QLabel(self.widget_52)
        self.label_Unfold.setMaximumSize(QtCore.QSize(20, 20))
        font = QtGui.QFont()
        font.setPointSize(9)
        self.label_Unfold.setFont(font)
        self.label_Unfold.setText("")
        self.label_Unfold.setPixmap(QtGui.QPixmap(":/\u5c55\u5f00.png"))
        self.label_Unfold.setScaledContents(True)
        self.label_Unfold.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignVCenter | QtCore.Qt.AlignTop)
        self.label_Unfold.setObjectName("label_Unfold")
        self.horizontalLayout_39.addWidget(self.label_Unfold)

        self.widget_55 = QtWidgets.QWidget(self.widget_52)
        self.widget_55.setObjectName("widget_55")
        self.verticalLayout_13 = QtWidgets.QVBoxLayout(self.widget_55)
        self.verticalLayout_13.setContentsMargins(-1, 0, -1, 0)
        self.verticalLayout_13.setObjectName("verticalLayout_13")

        # Label Instrument 2
        self.label_Instrument_2 = QtWidgets.QLabel(self.widget_55)
        self.label_Instrument_2.setObjectName("label_Instrument_2")
        self.label_Instrument_2.setText('直流电阻测试仪')
        self.verticalLayout_13.addWidget(self.label_Instrument_2)

        self.horizontalLayout_39.addWidget(self.widget_55)
        self.horizontalLayout_37.addWidget(self.widget_52)

        # Spacer item
        spacerItem3 = QtWidgets.QSpacerItem(623, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_37.addItem(spacerItem3)

        # Label List
        self.label_List = QtWidgets.QLabel(self)
        self.label_List.setMaximumSize(QtCore.QSize(30, 30))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.label_List.setFont(font)
        self.label_List.setText("")
        self.label_List.setPixmap(QtGui.QPixmap(":/\u6570\u636e.png"))
        self.label_List.setScaledContents(True)
        self.label_List.setObjectName("label_List")
        self.horizontalLayout_37.addWidget(self.label_List)

        # Label Info
        self.label_Chart = QtWidgets.QLabel(self)
        self.label_Chart.mousePressEvent = lambda event: self.Clicked_Info()
        self.label_Chart.setMaximumSize(QtCore.QSize(30, 30))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.label_Chart.setFont(font)
        self.label_Chart.setText("")
        self.label_Chart.setPixmap(QtGui.QPixmap(":/\u7ba1\u7406.png"))
        self.label_Chart.setScaledContents(True)
        self.label_Chart.setObjectName("label_Chart")
        self.horizontalLayout_37.addWidget(self.label_Chart)

        # Label Report
        self.label_Report = QtWidgets.QLabel(self)
        self.label_Report.setMaximumSize(QtCore.QSize(30, 30))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.label_Report.setFont(font)
        self.label_Report.setText("")
        self.label_Report.setPixmap(QtGui.QPixmap(":/\u62a5\u544a.png"))
        self.label_Report.setScaledContents(True)
        self.label_Report.setObjectName("label_Report")
        self.horizontalLayout_37.addWidget(self.label_Report)

        # Label Refresh
        self.label_Refresh = QtWidgets.QLabel(self)
        self.label_Refresh.setMaximumSize(QtCore.QSize(30, 30))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.label_Refresh.setFont(font)
        self.label_Refresh.setText("")
        self.label_Refresh.setPixmap(QtGui.QPixmap(":/\u5237\u65b0.png"))
        self.label_Refresh.setScaledContents(True)
        self.label_Refresh.setObjectName("label_Refresh")
        self.horizontalLayout_37.addWidget(self.label_Refresh)

        self.mainLayout.addLayout(self.horizontalLayout_37)

        self.tableWidget = QtWidgets.QTableWidget(self)
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setColumnCount(8)
        self.tableWidget.setHorizontalHeaderLabels([
            "测试时间", "测试模式", "测试电流(A)", "电阻A(mΩ)", "电阻B(mΩ)", "电阻C(mΩ)", "最大不平衡率(%)", "操作"
        ])
        self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.tableWidget.verticalHeader().setVisible(False)
        self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)

        self.mainLayout.addWidget(self.tableWidget)

        self.tableWidget.hide()

        # 折线图
        self.canvas = FigureCanvas(plt.Figure())
        self.mainLayout.addWidget(self.canvas)


# 回路电阻测试仪的widget
class M_LR_Widget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(M_LR_Widget, self).__init__(parent)

        # self.parent = parent

        self.setObjectName("m_lr_widget")
        self.setMinimumHeight(300)

        self.mainLayout = QtWidgets.QVBoxLayout(self)
        self.mainLayout.setObjectName("mainLayout")

        self.horizontalLayout_37 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_37.setObjectName("horizontalLayout_37")

        self.widget_52 = QtWidgets.QWidget(self)
        self.widget_52.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.widget_52.setAutoFillBackground(False)
        self.widget_52.setObjectName("widget_52")
        self.horizontalLayout_39 = QtWidgets.QHBoxLayout(self.widget_52)
        self.horizontalLayout_39.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_39.setSpacing(0)
        self.horizontalLayout_39.setObjectName("horizontalLayout_39")

        # Label Unfold
        self.label_Unfold = QtWidgets.QLabel(self.widget_52)
        self.label_Unfold.setMaximumSize(QtCore.QSize(20, 20))
        font = QtGui.QFont()
        font.setPointSize(9)
        self.label_Unfold.setFont(font)
        self.label_Unfold.setText("")
        self.label_Unfold.setPixmap(QtGui.QPixmap(":/\u5c55\u5f00.png"))
        self.label_Unfold.setScaledContents(True)
        self.label_Unfold.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignVCenter | QtCore.Qt.AlignTop)
        self.label_Unfold.setObjectName("label_Unfold")
        self.horizontalLayout_39.addWidget(self.label_Unfold)

        self.widget_55 = QtWidgets.QWidget(self.widget_52)
        self.widget_55.setObjectName("widget_55")
        self.verticalLayout_13 = QtWidgets.QVBoxLayout(self.widget_55)
        self.verticalLayout_13.setContentsMargins(-1, 0, -1, 0)
        self.verticalLayout_13.setObjectName("verticalLayout_13")

        # Label Instrument 2
        self.label_Instrument_2 = QtWidgets.QLabel(self.widget_55)
        self.label_Instrument_2.setObjectName("label_Instrument_2")
        self.label_Instrument_2.setText('回路电阻测试仪')
        self.verticalLayout_13.addWidget(self.label_Instrument_2)

        self.horizontalLayout_39.addWidget(self.widget_55)
        self.horizontalLayout_37.addWidget(self.widget_52)

        # Spacer item
        spacerItem3 = QtWidgets.QSpacerItem(623, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_37.addItem(spacerItem3)

        # Label List
        self.label_List = QtWidgets.QLabel(self)
        self.label_List.setMaximumSize(QtCore.QSize(30, 30))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.label_List.setFont(font)
        self.label_List.setText("")
        self.label_List.setPixmap(QtGui.QPixmap(":/\u6570\u636e.png"))
        self.label_List.setScaledContents(True)
        self.label_List.setObjectName("label_List")
        self.horizontalLayout_37.addWidget(self.label_List)

        # Label Info
        self.label_Chart = QtWidgets.QLabel(self)
        self.label_Chart.mousePressEvent = lambda event: self.Clicked_Info()
        self.label_Chart.setMaximumSize(QtCore.QSize(30, 30))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.label_Chart.setFont(font)
        self.label_Chart.setText("")
        self.label_Chart.setPixmap(QtGui.QPixmap(":/\u7ba1\u7406.png"))
        self.label_Chart.setScaledContents(True)
        self.label_Chart.setObjectName("label_Chart")
        self.horizontalLayout_37.addWidget(self.label_Chart)

        # Label Report
        self.label_Report = QtWidgets.QLabel(self)
        self.label_Report.setMaximumSize(QtCore.QSize(30, 30))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.label_Report.setFont(font)
        self.label_Report.setText("")
        self.label_Report.setPixmap(QtGui.QPixmap(":/\u62a5\u544a.png"))
        self.label_Report.setScaledContents(True)
        self.label_Report.setObjectName("label_Report")
        self.horizontalLayout_37.addWidget(self.label_Report)

        # Label Refresh
        self.label_Refresh = QtWidgets.QLabel(self)
        self.label_Refresh.setMaximumSize(QtCore.QSize(30, 30))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.label_Refresh.setFont(font)
        self.label_Refresh.setText("")
        self.label_Refresh.setPixmap(QtGui.QPixmap(":/\u5237\u65b0.png"))
        self.label_Refresh.setScaledContents(True)
        self.label_Refresh.setObjectName("label_Refresh")
        self.horizontalLayout_37.addWidget(self.label_Refresh)

        self.mainLayout.addLayout(self.horizontalLayout_37)

        self.tableWidget = QtWidgets.QTableWidget(self)
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setColumnCount(5)
        self.tableWidget.setHorizontalHeaderLabels([
            "测试时间", "实测电阻(mΩ)", "实测电流(mA)", "实测电压(mV)", "操作"
        ])
        self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.tableWidget.verticalHeader().setVisible(False)
        self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)

        self.mainLayout.addWidget(self.tableWidget)

        self.tableWidget.hide()

        # 折线图
        self.canvas = FigureCanvas(plt.Figure())
        self.mainLayout.addWidget(self.canvas)


# 接地导通仪的widget
class M_EC_Widget(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(M_EC_Widget, self).__init__(parent)

        # self.parent = parent

        self.setObjectName("m_ec_widget")
        self.setMinimumHeight(300)

        self.mainLayout = QtWidgets.QVBoxLayout(self)
        self.mainLayout.setObjectName("mainLayout")

        self.horizontalLayout_37 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_37.setObjectName("horizontalLayout_37")

        self.widget_52 = QtWidgets.QWidget(self)
        self.widget_52.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.widget_52.setAutoFillBackground(False)
        self.widget_52.setObjectName("widget_52")
        self.horizontalLayout_39 = QtWidgets.QHBoxLayout(self.widget_52)
        self.horizontalLayout_39.setContentsMargins(0, 0, 0, 0)
        self.horizontalLayout_39.setSpacing(0)
        self.horizontalLayout_39.setObjectName("horizontalLayout_39")

        # Label Unfold
        self.label_Unfold = QtWidgets.QLabel(self.widget_52)
        self.label_Unfold.setMaximumSize(QtCore.QSize(20, 20))
        font = QtGui.QFont()
        font.setPointSize(9)
        self.label_Unfold.setFont(font)
        self.label_Unfold.setText("")
        self.label_Unfold.setPixmap(QtGui.QPixmap(":/\u5c55\u5f00.png"))
        self.label_Unfold.setScaledContents(True)
        self.label_Unfold.setAlignment(QtCore.Qt.AlignLeading | QtCore.Qt.AlignVCenter | QtCore.Qt.AlignTop)
        self.label_Unfold.setObjectName("label_Unfold")
        self.horizontalLayout_39.addWidget(self.label_Unfold)

        self.widget_55 = QtWidgets.QWidget(self.widget_52)
        self.widget_55.setObjectName("widget_55")
        self.verticalLayout_13 = QtWidgets.QVBoxLayout(self.widget_55)
        self.verticalLayout_13.setContentsMargins(-1, 0, -1, 0)
        self.verticalLayout_13.setObjectName("verticalLayout_13")

        # Label Instrument 2
        self.label_Instrument_2 = QtWidgets.QLabel(self.widget_55)
        self.label_Instrument_2.setObjectName("label_Instrument_2")
        self.label_Instrument_2.setText('接地导通仪')
        self.verticalLayout_13.addWidget(self.label_Instrument_2)

        self.horizontalLayout_39.addWidget(self.widget_55)
        self.horizontalLayout_37.addWidget(self.widget_52)

        # Spacer item
        spacerItem3 = QtWidgets.QSpacerItem(623, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
        self.horizontalLayout_37.addItem(spacerItem3)

        # Label List
        self.label_List = QtWidgets.QLabel(self)
        self.label_List.setMaximumSize(QtCore.QSize(30, 30))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.label_List.setFont(font)
        self.label_List.setText("")
        self.label_List.setPixmap(QtGui.QPixmap(":/\u6570\u636e.png"))
        self.label_List.setScaledContents(True)
        self.label_List.setObjectName("label_List")
        self.horizontalLayout_37.addWidget(self.label_List)

        # Label Info
        self.label_Chart = QtWidgets.QLabel(self)
        self.label_Chart.mousePressEvent = lambda event: self.Clicked_Info()
        self.label_Chart.setMaximumSize(QtCore.QSize(30, 30))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.label_Chart.setFont(font)
        self.label_Chart.setText("")
        self.label_Chart.setPixmap(QtGui.QPixmap(":/\u7ba1\u7406.png"))
        self.label_Chart.setScaledContents(True)
        self.label_Chart.setObjectName("label_Chart")
        self.horizontalLayout_37.addWidget(self.label_Chart)

        # Label Report
        self.label_Report = QtWidgets.QLabel(self)
        self.label_Report.setMaximumSize(QtCore.QSize(30, 30))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.label_Report.setFont(font)
        self.label_Report.setText("")
        self.label_Report.setPixmap(QtGui.QPixmap(":/\u62a5\u544a.png"))
        self.label_Report.setScaledContents(True)
        self.label_Report.setObjectName("label_Report")
        self.horizontalLayout_37.addWidget(self.label_Report)

        # Label Refresh
        self.label_Refresh = QtWidgets.QLabel(self)
        self.label_Refresh.setMaximumSize(QtCore.QSize(30, 30))
        font = QtGui.QFont()
        font.setPointSize(13)
        self.label_Refresh.setFont(font)
        self.label_Refresh.setText("")
        self.label_Refresh.setPixmap(QtGui.QPixmap(":/\u5237\u65b0.png"))
        self.label_Refresh.setScaledContents(True)
        self.label_Refresh.setObjectName("label_Refresh")
        self.horizontalLayout_37.addWidget(self.label_Refresh)

        self.mainLayout.addLayout(self.horizontalLayout_37)

        self.tableWidget = QtWidgets.QTableWidget(self)
        self.tableWidget.setMaximumHeight(200)
        self.tableWidget.setObjectName("tableWidget")
        self.tableWidget.setColumnCount(4)
        self.tableWidget.setHorizontalHeaderLabels([
            "测试时间", "实测电阻(mΩ)", "实测电流(mA)", "操作"
        ])
        self.tableWidget.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.tableWidget.verticalHeader().setVisible(False)
        self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers)

        self.mainLayout.addWidget(self.tableWidget)

        self.tableWidget.hide()

        # 折线图
        self.canvas = FigureCanvas(plt.Figure())
        self.mainLayout.addWidget(self.canvas)


if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)
    mainWindow = QtWidgets.QMainWindow()
    centralWidget = M_EC_Widget()
    mainWindow.setCentralWidget(centralWidget)
    mainWindow.show()
    sys.exit(app.exec_())
